#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int p[N];

struct p {
    int d, v, a;
}f[N];

int flag[N];

int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);

    int t;
    cin >> t;
    while (t--) {
        int n, m, L, V;
        cin >> n >> m >> L >> V;
        for (int i = 1; i <= n; i++) {
            cin >> f[i].d >> f[i].v >> f[i].a;
        }
        for (int i = 1; i <= m; i++) {
            cin >> p[i];
        }
        for (int i = 1; i <= m; i++) {
            flag[i] = 0;
        }
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            if (f[i].a == 0) {
                for (int lc = f[i].d; lc <= L; lc++) {
                    int f1 = 0;
                    for (int j = 1; j <= m; j++) {
                        if (lc == p[j]) {
                            if (f[i].v > V) {
                                cnt++;
                                flag[j] = 1;
                                f1 = 1;
                                break;
                            }
                            break;
                        }
                    }
                    if (f1 == 1) {
                        break;
                    }
                }
            }

        }
        int ct = 0;
        for (int i = 1; i <= m; i++) {
            if (flag[i] != 1) {
                ct++;
            }
        }
        cout << cnt << " " << ct << endl;
    }

    return 0;

    fclose(stdin);
    fclose(stdout);
}
